function addformdiscount()
{
   $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addFrmPlug featureclass">'+dataform['discount']+"</div>");
   var rownow=rowdiv;
   var rowchecknow=0;
   //initialize($('#feature'+rownow+' .mapdata'));

     
     
$('#feature'+rownow+' .deleterowbutton').click(function(){
       
        $('#feature'+rownow).remove();
        
       });
$( "#feature"+rownow+' input[name="discountstartdate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( "#feature"+rownow+' input[name="discountenddate[]"]' ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#feature"+rownow+' input[name="discountenddate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( "#feature"+rownow+' input[name="discountstartdate[]"]' ).datepicker( "option", "maxDate", selectedDate );
}
});


$('#feature'+rownow+' input[name="discountgenerate[]"]').click(function(){
 
     var parem=new Array(); 
     $.post(serviceinfo+"postmedthodplugin",{classset:'discount',medthodset:"generatediscount",parem:parem},
     function(data){

     $('#feature'+rownow+' input[name="discountcode[]"]').val(data.data);

     });
       
     
        
});
  
   
  
   rowdiv++;
}
function saveformdiscount(id,plugid)
{
    var obj={};
          obj={
                   plugid:plugid,
                   price:$("#"+id+' input[name="discountprice[]"]').val(),
                   name:$("#"+id+' input[name="discountname[]"]').val(),
                   code:$("#"+id+' input[name="discountcode[]"]').val(),
                   startdate:$("#"+id+' input[name="discountstartdate[]"]').val(),
                   enddate:$("#"+id+' input[name="discountenddate[]"]').val()
                   
                   };
    //obj={plugid:plugid,lat:$("#"+id+' input[name="lat[]"]').val(),lng:$("#"+id+' input[name="lng[]"]').val(),detail:$("#"+id+' input[name="detail[]"]').val()};
    return obj;

}
function getformdiscount(dataplugin)
{

var code = '<div class="ldIt wrpFrmLd clBg4">\n';
code += '<div class="wrpHdInfoGen mgBtm10">\n';
code += '<h2 class="clTxt2 fs04">Discount</h2>\n';
code += '</div>\n';
code += '<table class="tbGenInfo tbFrmLd clTxt3 fs03">\n';
code += '<tbody><tr>\n';
code += '<th>Discount Name</th>\n';
code += '<td>'+dataplugin['name']+'</td>\n';
code += '</tr>\n';
code += '<tr>\n';
code += '<th>Value Discount</th>\n';
code += '<td>'+dataplugin['price']+' Baht</td>\n';
code += '</tr>\n';
code += '<tr>\n';
code += '<th>Coupon Code</th>\n';
code += '<td>'+dataplugin['code']+'</td>\n';
code += '</tr>\n';
code += '<tr>\n';
code += '<th>Period</th>\n';
code += '<td>'+dataplugin['startnewdate']+' - '+dataplugin['endnewdate']+'</td>\n';
code += '</tr>\n';
code += '</tbody></table>\n';
code += '</div>';

return code;

}
function editformdiscount(datarow)  
{
             addformdiscount();
             var rownow= rowdiv-1;
             $('#feature'+rownow+' input[name="discountprice[]"]').val(datarow.price);
             $('#feature'+rownow+' input[name="discountname[]"]').val(datarow.name);
             $('#feature'+rownow+' input[name="discountcode[]"]').val(datarow.code);

             
             
             
             if(datarow.startnewdate!="00/00/0000")$('#feature'+rownow+'  input[name="discountstartdate[]"]').val(datarow.startnewdate);
             if(datarow.endnewdate!="00/00/0000")$('#feature'+rownow+'  input[name="discountenddate[]"]').val(datarow.endnewdate);

              
}

